package org.tio.sitexxx.im.client.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;
import org.tio.sitexxx.im.common.Command;
import org.tio.sitexxx.im.common.CommandHandler;
import org.tio.sitexxx.im.common.ImPacket;
import org.tio.sitexxx.im.common.bs.GroupChatNtf;
import org.tio.sitexxx.service.vo.SimpleUser;
import org.tio.utils.json.Json;

/**
 * 进群响应处理者
 * @author tanyaowu
 * 2016年5月9日 上午11:46:24
 */
@CommandHandler(Command.GROUP_CHAT_NTY)
public class GroupChatNtfHandler implements ImClientHandler {
	private static Logger log = LoggerFactory.getLogger(GroupChatNtfHandler.class);

	public GroupChatNtfHandler() {

	}

	@SuppressWarnings("unused")
	@Override
	public void handler(ImPacket packet, ChannelContext channelContext) throws Exception {
		//		ImSessionContext imSessionContext = (ImSessionContext) channelContext.getAttribute(Const.IM_SESSION_KEY);
		//		log.info("{}, {}", channelContext, packet.getBodyStr());
		System.out.println(packet.getBodyStr());
		GroupChatNtf[] groupChatNtfs = Json.toBean(packet.getBodyStr(), GroupChatNtf[].class);
		for (GroupChatNtf groupChatNtf : groupChatNtfs) {
			String c = groupChatNtf.getC(); //聊天内容
			SimpleUser fromUser = groupChatNtf.getF(); //聊天发起人
			String g = groupChatNtf.getG(); //
			Long t = groupChatNtf.getT();
			log.error("tio-site-im-client只是用来做im压力测试的客户端，并不实现完整的业务逻辑，请悉知！（压测时请关闭日志）");
			log.error(fromUser.getN() + "说:" + c);
		}
	}

}
